package stock;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Component;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import stock.model.Sunfa20chengjiaoModel;

@Component
@SuppressWarnings("all")
public class Sunfa5 implements Sunfa5Interface {

	/**
	 * 得到昨日 涨停的股票
	 * 
	 * 
	 * @param json
	 */
	@Override
	public void fajiazhifu() {
		// TODO Auto-generated method stub

		//
		String sql = "select DISTINCT(t.code) from stockqq t ";

		Session session = ContextUtil.getSessionFactory1().openSession();
		List<String> list = session.createSQLQuery(sql).list();

		String sql1 = "select t.date, t.shizhi,t.zhangdiefu,t.huanshoulv,t.dqj from stockqq t where t.code =?0 ORDER BY t.date desc limit 0,20";

		List<String> str3zheng = new ArrayList<String>();
		List<String> str4zheng = new ArrayList<String>();
		List<String> str5zheng = new ArrayList<String>();

		for (int i = 0; i < list.size(); i++) {
			List<Object[]> list2 = session.createSQLQuery(sql1).setParameter(0, list.get(i)).list();
			if (list2 != null && list2.size() >= 2) {
				Object[] obj1 = list2.get(0);
				Object[] obj2 = list2.get(1);
				Object[] obj3 = list2.get(2);
				Object[] obj4 = list2.get(3);
				Object[] obj5 = list2.get(4);
				if (Float.parseFloat(obj1[1] + "") < 20) {
					continue;
				}
				Float zdf1 = Float.parseFloat(obj1[2] + "");
				Float zdf2 = Float.parseFloat(obj2[2] + "");
				Float zdf3 = Float.parseFloat(obj3[2] + "");
				Float zdf4 = Float.parseFloat(obj4[2] + "");
				Float zdf5 = Float.parseFloat(obj5[2] + "");

				Float hsl1 = Float.parseFloat(obj1[3] + "");
				Float hsl2 = Float.parseFloat(obj1[3] + "");
				Float hsl3 = Float.parseFloat(obj1[3] + "");

				// 连续三天为正
				if (zdf1 >= 0 && zdf2 >= 0 && zdf3 >= 0) {
					str3zheng.add(list.get(i));
				}
				// 连续四天为正
				if (zdf1 >= 0 && zdf2 >= 0 && zdf3 >= 0 && zdf4 >= 0) {
					str4zheng.add(list.get(i));
				}
				// 连续五天为正
				if (zdf1 >= 0 && zdf2 >= 0 && zdf3 >= 0 && zdf4 >= 0 && zdf5 >= 0) {
					str5zheng.add(list.get(i));
				}

				if (hsl2 >= hsl1 && hsl3 >= hsl2) {

				}
			}
		}

		System.out.println("连续三天为正：" + str3zheng.size());
		System.out.println(JSONArray.fromObject(str3zheng).toString());
		System.out.println("连续四天为正：" + str4zheng.size());
		System.out.println(JSONArray.fromObject(str4zheng).toString());
		System.out.println("连续五天为正：" + str5zheng.size());
		System.out.println(JSONArray.fromObject(str5zheng).toString());

//		session.beginTransaction();

//		session.createSQLQuery(sql10).executeUpdate();
//		session.save(sm);
//		session.getTransaction().commit();
//		session.clear();
//		session.close();
	}

}
